//
//  GonggaoListVC.m
//  SSC
//
//  Created by 红沙尘 on 17/6/10.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "GonggaoListVC.h"
#import "GonggaoDetailVC.h"

@interface GonggaoListVC ()
{
    NSMutableArray *gonggaoArray;
}
@end

@implementation GonggaoListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"平台公告"];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return gonggaoArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GGCell"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:@"GGCell"];
        cell.textLabel.font = [MTool fontOfSize:14];
        cell.textLabel.textColor = [UIColor colorWithHexString:@"#666666"];
        cell.imageView.image = LoadImage(@"home_4");
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, ScreenWidth, LineHeight)];
        lineView.backgroundColor = COLOR_CCCCCC;
        [cell addSubview:lineView];
    }
    
    NSDictionary *dict = gonggaoArray[indexPath.row];
    cell.textLabel.text = dict[@"title"];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    GonggaoDetailVC *vc = [[GonggaoDetailVC alloc] initWithDict:gonggaoArray[indexPath.row]];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - setup

- (void)setupData {
    
    gonggaoArray = [[NSMutableArray alloc] init];

    [SSCRequest queryNoticeListSuccess:^(NSDictionary *responseObject) {
        NSArray *data = responseObject[@"data"];
        [gonggaoArray addObjectsFromArray:data];
        [mainTableView reloadData];
    } fail:^(NSError *error) {
        
    }];
}

- (void)setupUI {
    mainTableView.rowHeight = 44;
    mainTableView.estimatedRowHeight = 44;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
